#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include "cppjieba/Jieba.hpp"
namespace ParseModel
{
    class isparse
    {
    public:
        static bool ReadFile(const std::string &title, std::string *ret)
        {
            // 使用ifstream读取文件
            std::ifstream in(title, std::ios::in);
            if (!in.is_open()) // 判断文件是否打开成功
            {
                std::cout << "open file failed" << std::endl;
                return false;
            }
            // 读取文件内容到ret
            std::string line;
            while (std::getline(in, line)) // 逐行读取文件内容
            {
                *ret += line; // 将每行内容添加到ret中
            }
            in.close();
            return true;
        }
    };
    class StringUtil
    {
    public:
        static void CutString(const std::string &target, std::vector<std::string> *out, const std::string &sep)
        {
            boost::split(*out, target, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";
    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;
        public:
        static void CutString(const std::string &str,std::vector<std::string> *out)
        {
            jieba.CutForSearch(str,*out);
        }
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,
                          HMM_PATH,
                          USER_DICT_PATH,
                          IDF_PATH,
                          STOP_WORD_PATH);
}